package com.tanhua.dubbo.api;

/**
 * @Author: cl
 * @Date: 2022/5/2 - 05 - 02
 * @Description:
 */

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import com.tanhua.model.domain.BlackList;
import com.tanhua.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.Wrapper;

/**
 * 黑名单列表服务
 */
@DubboService
public class BlackListApiImpl implements BlackListApi {

    //用户信息表
    @Autowired
    private UserInfoMapper userInfoMapper;

    //黑名单表
    @Autowired
    private BlackListMapper blackListMapper;

    /**
     * 分页展示黑名单列表
     *
     * @param userId
     * @param page
     * @param size
     * @return
     */
    @Override
    public IPage<UserInfo> findByPage(Long userId, int page, int size) {

        //1、构建分页查询对象
        Page pages = new Page();
        //2、调用自定义子查询
        IPage<UserInfo> userInfoIPage = userInfoMapper.findBlackListByPage(pages, userId);
        return userInfoIPage;
    }

    /**
     * 删除黑名单列表人员
     *
     * @param userId
     * @param blackUserId
     */
    @Override
    public void delete(Long userId, Long blackUserId) {
        blackListMapper.delete(
                Wrappers.<BlackList>lambdaQuery()
                        .eq(BlackList::getUserId, userId)
                        .eq(BlackList::getBlackUserId, blackUserId)
        );
    }
}
